home *** CD-ROM | disk | FTP | other *** search
/ Programmer Power Tools / Programmer Power Tools.iso / progjrn / pj_7_2.arc / DEVCHAIN.ASM < prev    next >
Assembly Source File  |  1989-02-26  |  4KB  |  222 lines

  1. ;
  2. ; A device driver utility
  3. ; prints the chain of DOS device drivers 
  4. ;
  5. ; by Raymond Michels
  6. ;
  7. ;
  8. cseg    segment
  9.  
  10.     assume cs:cseg,ds:cseg
  11.  
  12.     org    100h
  13.  
  14. ddhead    struc
  15. next_dd        dd    0    ;
  16. attrib        dw    0    ;
  17. strat_ptr    dw    0    ;
  18. int_ptr        dw    0    ;
  19. dev_name    db    8 dup (0);
  20. ddhead    ends
  21.  
  22.  
  23.  
  24. begin:
  25.     mov    ax,es        ;get PSP segment for return
  26.     mov    cs:psp_seg,ax
  27.     mov    ax,cs
  28.     mov    ds,ax        ;set DS to our CS
  29.     mov    ss,ax
  30.     mov    sp,offset ourstk
  31. ;
  32.     mov    ah,52h        ;get dos variables
  33.     int    21h
  34.                 ;es:bx -> vars
  35.     add    bx,22h        ;get to nul device
  36.  
  37.     mov    dx,offset crlf    ;print headers
  38.     call    string_out
  39.     mov    dx,offset head0
  40.     call    string_out
  41.  
  42. loop1:
  43.     call    prt_dd        ;print device driver info
  44.     cmp    word ptr es:[bx],0FFFFh    ;check if last driver in chain
  45.     je    exit        ;yes - so exit
  46.     les    bx,es:[bx]    ;get address of next driver
  47.     jmp    short loop1        
  48.  
  49. exit:
  50.     mov    ax,cs:psp_seg
  51.     mov    ds,ax
  52.     mov    es,ax
  53.     mov    ah,0        ;exit to dos
  54.     int    21h
  55.  
  56.  
  57. prt_dd    proc    near        
  58. ;Print pertinent field of device driver header
  59. ;Input: ES:BX points to device driver header
  60. ;Output: None
  61.  
  62.     push    ax        ;save registers
  63.     push    bx
  64.     push    cx
  65.     push    dx
  66.     push    si
  67.  
  68.     mov    dx,es        ;segment of device driver
  69.     call    hex_to_ascii
  70.     mov    al,':'
  71.     call    char_out
  72.  
  73.     mov    dx,bx        ;offset of device driver
  74.     call    hex_to_ascii
  75.     mov    al,' '
  76.     call    char_out
  77.     mov    al,' '
  78.     call    char_out
  79.  
  80.     mov    dx,es:[bx.attrib]    ;attribute
  81.     call    hex_to_ascii
  82.     mov    al,' '
  83.     call    char_out
  84.     mov    al,' '
  85.     call    char_out
  86.  
  87.     mov    dx,es        ;Print SEG:OFS of Strategy
  88.     call    hex_to_ascii
  89.     mov    al,':'
  90.     call    char_out
  91.     mov    dx,es:[bx.strat_ptr]
  92.     call    hex_to_ascii
  93.     mov    al,' '
  94.     call    char_out
  95.  
  96.     mov    dx,es        ;Print SEG:OFS of Interrupt
  97.     call    hex_to_ascii
  98.     mov    al,':'
  99.     call    char_out
  100.     mov    dx,es:[bx.int_ptr]
  101.     call    hex_to_ascii
  102.  
  103.     mov    al,' '
  104.     call    char_out
  105.     mov    al,' '
  106.     call    char_out
  107.  
  108.     mov    ax,es:[bx.attrib];Print BLOCK or CHAR
  109.     and    ax,0f000h
  110.     test    ax,8000h
  111.     jnz    is_char        ;Has Character Attribute
  112.  
  113.     mov    dx,offset block    ;Print Out Block Info
  114.     call    string_out    
  115.     mov    al,' '
  116.     call    char_out
  117.  
  118.     mov    al,es:[bx+10]
  119.     add    al,48
  120.     call    char_out
  121.     jmp    prt_dd1
  122.  
  123. is_char:mov    dx,offset char    ;Print Out Character Info
  124.     call    string_out
  125.     mov    al,' '
  126.     call    char_out
  127.     mov    si,bx
  128.     add    si,10
  129.     mov    cx,8
  130.  
  131. is_char_loop:            ;Print Out Character Device Name
  132.     mov    al,es:[si]
  133.     inc    si    
  134.     call    char_out
  135.     loopnz    is_char_loop
  136.  
  137. prt_dd1:
  138.     mov    dx,offset crlf
  139.     call    string_out
  140.  
  141.     pop    si        ;restore registers
  142.     pop    dx
  143.     pop    cx
  144.     pop    bx
  145.     pop    ax
  146.     ret    
  147. prt_dd    endp
  148.  
  149. char_out proc near  ;output character in al
  150.     push    dx
  151.     mov    dl,al
  152.     mov    ah,2
  153.     int    21h
  154.     pop    dx
  155.     ret
  156. char_out    endp
  157.  
  158.  
  159. hex_to_ascii    proc    near    ;output hex word in dx 
  160.     push    cx
  161.     push    ax
  162.     mov    cx,4
  163. hex1:
  164.     push    cx
  165.     mov    cl,4
  166.     rol    dx,cl
  167.     mov    al,dl
  168.     and    al,0fh
  169.     daa
  170.     add    al,0f0h
  171.     adc    al,040h
  172.     call    char_out
  173.     pop    cx
  174.     loop    hex1
  175.     
  176.     pop    ax
  177.     pop    cx    
  178.     ret
  179. hex_to_ascii    endp
  180.  
  181. string_out    proc    near    ;print a string pointed to by DS:DX
  182.                 ;first byte of string is length
  183.  
  184.     push    ax
  185.     push    bx
  186.     push    cx
  187.     push    dx
  188.     mov    ah,40h
  189.     mov    bx,dx
  190.     inc    dx    ;point to string
  191.     mov    cl,[bx]    ;get length
  192.     mov    bx,1    ;standard output
  193.     int    21h
  194.     pop    dx
  195.     pop    cx
  196.     pop    bx
  197.     pop    ax
  198.     ret
  199. string_out    endp
  200.  
  201. ;
  202. ;data
  203. ;
  204.  
  205. head0    db    162,'     D E V I C E    D R I V E R    C H A I N      ',13,10
  206.         db        'Drv Addrs  Atrb  Strategy  Interrupt  Type  Name/Unit',13,10
  207.     db        '---------  ----  --------- ---------  ----- ---------',13,10
  208. block    db    5,'Block'
  209. char    db    5,'Char '
  210. crlf    db    2,13,10
  211. ;
  212. psp_seg    dw    0
  213.  
  214.     align 4
  215.     db    40 dup ('STACK   ')
  216. ourstk    dw    ?
  217.  
  218. cseg    ends
  219. end    begin
  220.  
  221.  
  222.